
import { createI18n } from 'vue-i18n'

import zh from './zh-cn.ts'
import en from './en-us.ts'

const defineLang = "en-us"
// 组定义的语言
const messages = {
    "en-us": en,
    "zh-cn": zh,
}
const language = (navigator.language || defineLang).toLocaleLowerCase() // 这是获取浏览器的语言
const i18n = createI18n({
    locale: localStorage.getItem('lang') || language.split('-')[0] || defineLang, // 首先从缓存里拿，没有的话就用浏览器语言，
    fallbackLocale: 'zh-cn', // 设置备用语言
    messages,
    legacy: false,
    globalInjection:true,
})
export const I18n = i18n

// 组件库语言
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import enUs from 'ant-design-vue/es/locale/en_US';
import 'dayjs/locale/zh-cn';
export const Lang = {
    "zh-cn": {
        value: "zh-cn",
        label: "简体中文",
        antd: zhCN,
    },
    "en-us": {
        value: "en-us",
        label: "English",
        antd: enUs,
    }
}
export const FuncLang = (v: keyof typeof Lang) => {
    return Lang[v]
}
export const _t = (v:string, data = {}) => {
    const { t } = i18n.global
    return t(v, data)
}




